package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.entity.Buyer;
import com.shop.entity.Category;
import com.shop.entity.Result;
import com.shop.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * description: 类目管理
 *
 * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
 * @version 1.0
 * @date 2018/10/10 17:09
 **/
@Controller
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;
    /**
     * description:<类目管理的界面>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/categoryList")
    public ModelAndView buyersList(){
        ModelAndView view = new ModelAndView("categoryList");
        return view;
    }

    /**
     * description:<类目管理查找>
     *
     * @param
     * @return
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date 2018/10/9 13:40
     **/
    @RequestMapping("/getCategoryList")
    @ResponseBody
    public PageInfo<Category> getCategoryList(@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "rows", defaultValue = "2") Integer rows, Category category) {
        PageInfo<Category> pageInfo =  categoryService.findCategory(page,rows,category);
        return pageInfo;
    }


    /**
     * description:<添加会员的页面跳转>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/toAddCategory")
    public ModelAndView toAddCategory(){
        ModelAndView view = new ModelAndView("addCategory");
        return view;
    }

    /**
     * description:<新增会员管理>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/doAddCategory")
    @ResponseBody
    public Result doAddCategory(Category category){
        return categoryService.addCategory(category);
    }

    /**
     * description:<修改类目的页面跳转>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/toModifyCategory")
    public ModelAndView toModifyCategory(){
        ModelAndView view = new ModelAndView("modifyCategory");
        return view;
    }


    /**
     * description:<修改会员的页面>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/doModifyCategory")
    @ResponseBody
    public Result doModifyCategory(Category category){
        return categoryService.modifyCategory(category);
    }

    /**
     * description:<修改类目的页有效性>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/doShelfOrObtainedCategory")
    @ResponseBody
    public Result doShelfOrObtainedCategory(@RequestParam(value = "categoryId") String categoryId){
        return categoryService.updateCategoryStatu(categoryId);
    }

    /**
     * description:<查询所有有效的类目>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/9 13:40
     * @param
     * @return
     **/
    @RequestMapping("/findCategoryAll")
    @ResponseBody
    public List<Category> findCategoryAll(){
        return categoryService.findCategoryAll();
    }
}
